package cn.stylefeng.guns.modular.info.mapper;

import cn.stylefeng.guns.modular.info.entity.Game;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface GameMapper extends BaseMapper<Game> {

    Page<Game> findGameByParam(Page page, @Param("param") Map<String, String> param);

    @Select("SELECT t.name FROM t_season t where t.fk_league_id=#{fkLeagueId}  ORDER BY priority desc")
    List<String> groupGameYear(@Param("fkLeagueId") String fkLeagueId);

    @Select("SELECT * FROM (SELECT COUNT(*) fROM t_game t where fk_league_id=#{fkLeagueId} and t.run = 1) a LIMIT 1")
    Integer groupGameRunCount(@Param("fkLeagueId") String fkLeagueId);

    @Select("SELECT t.fk_league_id as id,count(*) as count FROM t_game t where (t.own_goal_teamA =1 or t.own_goal_teamB =1) GROUP BY t.fk_league_id")
    List<Map<String, Object>> groupGameOwnGoalCount();

    @Select("SELECT t.fk_league_id as id,count(*) as count FROM t_game t where (first_halfA >= 1 and first_halfB >= 1 and second_halfA >= 1 and second_halfB >= 1) GROUP BY t.fk_league_id")
    List<Map<String, Object>> groupGameHalfGoalCount();
}
